#!/usr/bin/env python
# encoding: utf-8
'''
@author: wangjianrong
@software: pycharm
@file: split_gif.py
@time: 2020/10/10 9:54
@desc:
'''

from PIL import Image
import os

"""
  将一张GIF动图分解到指定文件夹
  src_path：要分解的gif的路径
  dest_path：保存后的gif路径
"""


def gifSplit(src_path, dest_path, suffix="png"):
    img = Image.open(src_path)
    for i in range(img.n_frames):
        img.seek(i)
        new = Image.new("RGBA", img.size)
        new.paste(img)
        save_path = os.path.join(dest_path,str(i).zfill(6)+'.{}'.format(suffix))
        new.save(save_path)


# gifSplit('明亮.gif', r'./pics')